﻿using System;
using System.Windows;
using compshop.Infrastructure.CompShopDataService;

namespace compshop.Modules.PositionList.View
{
    /// <summary>
    /// Логика взаимодействия для PositionDialog.xaml
    /// </summary>
    public partial class PositionDialog : Window
    {
        public Position Position { set; get; }

        public PositionDialog()
        {
            InitializeComponent();
        }

         public PositionDialog(Position position) 
            : this()
        {
            Position = position;
            DataContext = this;
        }

        private void btnOK_Click(object sender, RoutedEventArgs e)
        {
            if (tbName.Text != String.Empty && tbSalary.Text != String.Empty)
            {
                decimal d = 0;
                if (Decimal.TryParse(tbSalary.Text, out d))
                {
                    if (Position == null)
                        Position = new Position();
                    Position.Name = tbName.Text;
                    Position.Salary = d;
                    DialogResult = true;
                    Close();
                }
                else MessageBox.Show(Resource.msgBadSalaryFormat);
            }
            else MessageBox.Show(Resource.msgAllFieldsMustBeFilled);         
        }

        private void btnCancel_Click(object sender, RoutedEventArgs e)
        {
            DialogResult = false;
            Close();
        }
    }
}
